/*
 * Copyright (c) 2017 5utrip.com. All Rights Reserved.
 */
package com.guoyu.project.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.google.common.collect.Maps;
import com.guoyu.project.model.School;
import org.springframework.stereotype.Service;

import com.guoyu.project.model.Province;
import com.guoyu.project.common.constant.Constants;
import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.dao.ProvinceDao;

/**
 * 省份,业务类ProvinceService
 *
 * @author: xblibo Thu Jun 22 16:51:17 CST 2017
 * @version 1.0.0
 */
@Service
public class ProvinceService {

    @Resource
    private ProvinceDao provinceDao;

    /**
     * 保存省份数据
     *
     * @param province
     */
    public void saveProvince(Province province) {
        provinceDao.save(province);
    }

    /**
     * 更新省份实体
     *
     * @param province
     */
    public void updateProvince(Province province) {
        provinceDao.update(province);
    }

    /**
     * 删除省份数据
     *
     * @param provinceId
     */
    public void deleteById(int provinceId) {
        provinceDao.deleteById(provinceId);
    }

    /**
     * 根据id获取省份数据
     *
     * @param provinceId
     * @return
     */
    public Province queryById(int provinceId) {
        return provinceDao.queryById(provinceId);
    }

    /**
     * 根据条件分页查询省份数据
     *
     * @param offset
     * @param limit
     * @param params
     * @return
     */
    public Pagination<Province> queryProvinces(int offset, int limit, Map<String, Object> params) {
        // 根据条件获取总记录数
        int total = provinceDao.queryProvinceCount(params);

        if (null == params) {
            params = Maps.newHashMap();
        }
        params.put(Pagination.OFFSET, offset);
        params.put(Pagination.LIMIT, limit);

        // 分页查询数据
        List<Province> provinceList = provinceDao.queryProvinces(params);

        return new Pagination(offset, limit, total, provinceList);
    }

    public List<Province> queryAll() {
        Map<String, Object> params = Maps.newHashMap();
        return provinceDao.queryProvinces(params);
    }
}